<md-tab-header [selectedIndex]="selectedIndex" #tabHeader
               (indexFocused)="_focusChanged($event)"
               (selectFocusedIndex)="selectedIndex = $event">
  <div class="mat-tab-label" role="tab" md-tab-label-wrapper md-ripple
       *ngFor="let tab of _tabs; let i = index"
       [id]="_getTabLabelId(i)"
       [tabIndex]="selectedIndex == i ? 0 : -1"
       [attr.aria-controls]="_getTabContentId(i)"
       [attr.aria-selected]="selectedIndex == i"
       [class.mat-tab-label-active]="selectedIndex == i"
       [disabled]="tab.disabled"
       (click)="tabHeader.focusIndex = selectedIndex = i">

    <!-- If there is a label template, use it. -->
    <ng-template [ngIf]="tab.templateLabel">
      <ng-template [cdkPortalHost]="tab.templateLabel"></ng-template>
    </ng-template>

    <!-- If there is not a label template, fall back to the text label. -->
    <ng-template [ngIf]="!tab.templateLabel">{{tab.textLabel}}</ng-template>
  </div>
</md-tab-header>

<div class="mat-tab-body-wrapper" #tabBodyWrapper>
  <md-tab-body role="tabpanel"
               *ngFor="let tab of _tabs; let i = index"
               [id]="_getTabContentId(i)"
               [attr.aria-labelledby]="_getTabLabelId(i)"
               [class.mat-tab-body-active]="selectedIndex == i"
               [content]="tab.content"
               [position]="tab.position"
               [origin]="tab.origin"
               (onCentered)="_removeTabBodyWrapperHeight()"
               (onCentering)="_setTabBodyWrapperHeight($event)">
  </md-tab-body>
</div>
